import { updateUser } from '../../../services/usercenter/user';
import Toast from 'tdesign-miniprogram/toast/index';


Page({
  data: {
    nameValue: '',
  },
  onLoad(options) {
    const { name } = options;
    this.setData({
      nameValue: name,
    });
  },
  onSubmit() {
    // 修改用户名信息
    console.log(this.data.nameValue);
    updateUser({
      nickName:this.data.nameValue
    }).then(res=>{
      console.log(res.data);
      Toast({
        context: this,
        selector: '#t-toast',
        message: res.data.message,
        theme: 'success',
      });
    }).catch(error=>{
      Toast({
        context: this,
        selector: '#t-toast',
        message: res.data.message,
        theme: 'error',
      });
    })
    wx.navigateBack({ backRefresh: true });
  },
  clearContent() {
    this.setData({
      nameValue: '',
    });
  },
});
